package org.metasketch.graphics;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

@XStreamAlias("point2f")
public class Point2f {

	@XStreamAsAttribute
	double x;

	@XStreamAsAttribute
	double y;

	public Point2f(double x, double y) {
		this.x = x;
		this.y = y;
	}

	public void scale(double value) {
		x = x * value;
		y = y * value;
	}

	public double getX() {
		return x;
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getY() {
		return y;
	}

	public void setY(double y) {
		this.y = y;
	}

	public boolean withinRadius(double distance, Point2f point) {
		double distX = x - point.getX();
		double distY = y - point.getY();

		double bdist = distX * distX + distY * distY;

		if (bdist == 0)
			return true;

		double dist = Math.sqrt(bdist);

		if (dist < distance)
			return true;

		return false;

	}

}
